package com.steve.ai.controller;

import com.steve.ai.service.IChatStreamAssistant;
import dev.langchain4j.model.chat.ChatLanguageModel;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Author: STEVE
 * @Description: 对接AI大模型入口
 * @since: 2025-07-14
 */
@RestController
public class ChatController {

    /**
     * 引入语言模型
     */
    ChatLanguageModel chatLanguageModel;
    @Resource
    private IChatStreamAssistant streamAssistant;

    public ChatController(ChatLanguageModel chatLanguageModel) {
        this.chatLanguageModel = chatLanguageModel;
    }

    @GetMapping("/chat")
    public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
        return chatLanguageModel.generate(message);
    }

    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> stream(@RequestParam(value = "message", defaultValue = "Hello") String message) {
        Flux<String> stringFlux = streamAssistant.chat(message);
        return stringFlux;
    }

}
